package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.BtySuixingfu;
import cn.stylefeng.guns.sys.modular.system.mapper.BtySuixingfuMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.BtySuixingfuParam;
import cn.stylefeng.guns.sys.modular.system.model.result.BtySuixingfuResult;
import  cn.stylefeng.guns.sys.modular.system.service.BtySuixingfuService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liuy
 * @since 2022-04-27
 */
@Service
public class BtySuixingfuServiceImpl extends ServiceImpl<BtySuixingfuMapper, BtySuixingfu> implements BtySuixingfuService {

    @Override
    public void add(BtySuixingfuParam param){
        BtySuixingfu entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BtySuixingfuParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BtySuixingfuParam param){
        BtySuixingfu oldEntity = getOldEntity(param);
        BtySuixingfu newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BtySuixingfuResult findBySpec(BtySuixingfuParam param){
        return null;
    }

    @Override
    public List<BtySuixingfuResult> findListBySpec(BtySuixingfuParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(BtySuixingfuParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public boolean insertSuixingfu(List<BtySuixingfu> list) {
        return baseMapper.insertSuixingfu(list);
    }

    @Override
    public List<BtySuixingfuResult> sxfList() {
        return baseMapper.sxfList();
    }

    @Override
    public int updateStateByDm(BtySuixingfuParam param) {
     return baseMapper.updateStateByDm(param);
    }

    private Serializable getKey(BtySuixingfuParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BtySuixingfu getOldEntity(BtySuixingfuParam param) {
        return this.getById(getKey(param));
    }

    private BtySuixingfu getEntity(BtySuixingfuParam param) {
        BtySuixingfu entity = new BtySuixingfu();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
